Ext.define('Triends.view.PostLocationModify', {
	extend: 'Ext.form.Panel',
 	id: 'postlocationmodify',
	xtype: 'postlocationmodify',
	config:{
	fullscreen: true,
	showAnimation: 'slideIn',
	listeners: {
 		deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
				Ext.getCmp('titlelocationmodify').reset();
				Ext.getCmp('contentlocationmodify').reset();
				Ext.getCmp("continent3").reset();
 				Ext.getCmp("nation3").reset();
 			}
 	},
 	items: [
 		{
 			xtype: 'locationfield3'
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Title',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'titlelocationmodify'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Content',
 			items: [{
 				xtype: 'textareafield',
 				name: 'content',
 				minHeight: 200,
 				style: 'border:3px inset',
 				id: 'contentlocationmodify'
 			}]
 		},
 		{
 			xtype: 'button',
 			text: '등록',
 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 	width: '100%',
 			handler: function(){
 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
 				
 				var postinfopanel = Ext.getCmp("postinfolocationpanel");
 				var num = postinfopanel.getData().Number;
 				
 				var titlefield = Ext.getCmp('titlelocationmodify');
 				var contentfield = Ext.getCmp('contentlocationmodify');
 				var continentfield = Ext.getCmp("continent3");
 				var nationfield = Ext.getCmp("nation3");
 				var post = Ext.getCmp('post');
 				Ext.Ajax.request({
 					url: 'http://itscreater.cafe24.com/Triends/PostModify.jsp',
 					params: {
 						num: num, 
 						title: titlefield.getValue(), 
 						content: contentfield.getValue(),
 						continent: continentfield.getValue(),
 						nation: nationfield.getValue()
 					},
// 					callbackkey: 'callback',
 					success: function(response) {
 						Ext.Msg.alert('', '글이 수정되었습니다.', Ext.emptyFn);
 						
 						postLocationStore.setProxy({
							type: "jsonp",
							url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp',
							extraParams: {continent: continentfield.getValue(),
										  nation: nationfield.getValue()},
							callbackkey: 'callback',
							pageParam: 'pages',
							limitParam: 'rpp',
							reader: {
								type: "json",
								rootProperty: "results",
								totalProperty: "total"
							}
						})
						postLocationStore.loadPage(1);
 						
						localStorage.removeItem(continent);
						localStorage.removeItem(nation);
						localStorage.setItem("continent", continentfield.getValue());
						localStorage.setItem("nation", nationfield.getValue());
 						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage'
        					}));
        				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/post/postlocationlist'
        					}));
 					}
 				});
 			}	
 		}]
	}
});